import { prisma } from "../prisma/client";
import { PaginationUtil } from "../utils/pagination.util";
// 获取所有权限
export const getAllPermissions = async (
  page: number = 1,
  pageSize: number = 10,
  options: object = {}
) => {
  return PaginationUtil.paginate(prisma.permission, options, page, pageSize);
};

// 根据ID获取权限
export const getPermissionById = async (id: number) => {
  return await prisma.permission.findUnique({
    where: { id },
  });
};

// 创建权限
export const createPermission = async (data: {
  name: string;
  label?: string;
  description?: string;
}) => {
  return await prisma.permission.create({
    data,
  });
};

// 更新权限
export const updatePermission = async (
  id: number,
  data: {
    name?: string;
    label?: string;
    description?: string;
  }
) => {
  return await prisma.permission.update({
    where: { id },
    data,
  });
};

// 删除权限
export const deletePermission = async (id: number) => {
  return await prisma.permission.delete({
    where: { id },
  });
};
